<template>
	<view class="container">
		<view class="user-section">
			<view class="container_nav">
				<view class="container_navContainer">
					<view class="container_navImg">
						<image src="../../static/dkw.png"></image>
					</view>
					<view class="container_navImg">
						<image src="../../static/sz.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="bg"></view>
			<view class="user-info-box">
				<view>
					<image src="../../static/temp/missing-face.png" mode=""></image>
					<text @click="long()">{{nickname}}</text>
				</view>
			</view>
			<view class="vip-card-box">
				<view class="vip-card-Text">
					<view style="font-size: 30upx;">
						<image style="text-align: center;" src="../../static/zhu.png" mode=""></image>普通会员
					</view>
					<view>VIP权益</view>
					<view style="font-size: 25upx;">请联系管理员开通会员</view>
				</view>
				<image class="vip-card-img"></image>
			</view>
		</view>
		
		<view class="container" :style="[{
					transform: coverTransform,
					transition: coverTransition,
					top:top,
					
				}]" @touchstart="coverTouchstart"
		 @touchmove="coverTouchmove" @touchend="coverTouchend">
			<slot>
				<!-- <view class="cover-container"> -->
					<view class="cover-img">
						<image src="../../static/arc.png" mode=""></image>
					</view>
					<view class="order-section">
						<view class="order-sectionText" v-for="(item,index) in appData" :key="index" @click="order()">
							<view>
								<image :src="item.imgUrl"></image>
							</view>
							<text>{{item.title}}</text>
						</view>
					</view>
					<view class="history-section">
						<view class="history-Text" v-for="(item,index) in appNang" :key="index">
							<view @click="appDatas(index)">
								<image :src="item.imgUrl"></image>
								<text :class="index>=5?'lettel':''">{{item.title}}</text>
								<image :src="item.img" style="width: 30upx;height: 30upx;"></image>
							</view>
							<view class="history_img" v-if="index==0">
								<scroll-view :scroll-x='true'>
									<view class="imgs-content">
										<view v-for="(item,index) in history" :key="index" @longtap="longtap(item.id)">
											<image :src="item.spuImg"></image>
										</view>
									</view>
								</scroll-view>
							</view>
						</view>
					
					<uni-popup ref="popup" type="dialog">
						<uni-popup-dialog type="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm"></uni-popup-dialog>
					</uni-popup>
				</view>
			<!-- 	</view> -->
			</slot>
		
		</view>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		components: {
			uniPopup,
			uniPopupMessage,
			uniPopupDialog
		},
		props: {
			top: {
				type: String,
				default: () => '30%'
			},
		},
		data() {
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				history: [],
				Token: "",
				nickname: '',
				appData: [{
						title: '全部订单',
						imgUrl: '../../static/1.png'
					},
					{
						title: '待付款',
						imgUrl: '../../static/2.png'
					},
					{
						title: '待收货',
						imgUrl: '../../static/3.png'
					},
					{
						title: '退款/售后',
						imgUrl: '../../static/4.png'
					},
				],
				appNang: [{
						title: '浏览历史',
						imgUrl: '../../static/微信图片_202009221708005.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '地址管理',
						imgUrl: '../../static/wx1.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '我的收藏',
						imgUrl: '../../static/wx2.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '我的收藏',
						imgUrl: '../../static/wx3.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '个人资料',
						imgUrl: '../../static/wx4.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '关于',
						imgUrl: '../../static/wx5.png',
						img: '../../static/images/go-icon.png'
					},
					{
						title: '退出',
						imgUrl: '../../static/wx6.png',
						img: '../../static/images/go-icon.png'
					}
				]
			}
		},
		onLoad() {
			this.nickname = uni.getStorageSync('nickname')
			this.Token = uni.getStorageSync('Token')
			uni.request({
				url: this.$C.webUrl + 'm.api?_gp=footprint&_mt=getAllFootprint',
				header: {
					accessToken: this.Token
				},
				success: (res) => {
					console.log(res)
					this.history = res.data.data
				}

			})
		
		},
		mounted() {
			// this.remind()
		},
		methods: {
			// remind(){
			// 	if (this.Token == "") {} else {
			// 		uni.showModal({
			// 			title: '登录提示',
			// 			content: '您尚未登录，是否立即登录？',
			// 			success: function(res) {
			// 				if (res.confirm) {
			// 					console.log('用户点击确定');
			// 					uni.navigateTo({
			// 						url: '../rapidLogin/index'
			// 					})
			// 				} else if (res.cancel) {
			// 					console.log('用户点击取消');
			// 				}
			// 			}
			// 		});
			// 	}
			// },
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}
			
				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			},
			// 长按事件
			longtap(e){
				console.log(e)
				var _this=this;
				uni.showModal({
					title: '删除？',
					content: '您确定要删除此足迹吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('确定');
							uni.request({
								url:_this.$C.webUrl + `m.api?_gp=footprint&_mt=deleteFootprint&footprintId=${e}`,
								header: {
									accessToken:this.Token 
								},
								success: (res) => {
									console.log(res)
								}
							})
						} else if (res.cancel) {
							console.log('取消');
						}
					}
				});
			},
			order() {
				uni.navigateTo({
					url: '../order/list'
				})
			},
			long() {
				uni.navigateTo({
					url: '../rapidLogin/index'
				})
			},
			close(done) {
				done()
			},
			confirm(done, value) {
				// 输入框的值
				console.log(value)
				// TODO 做一些其他的事情，手动执行 done 才会关闭对话框
				// ...
				done()
			},
			open() {
				this.$refs.popup
			},

			appDatas(e) {
				if (e == 5) {
					uni.navigateTo({
						url: '../about/index'
					})
				}
				if (e == 2) {
					uni.navigateTo({
						url: '../product/index'
					})
				}
				if (e == 4) {
					uni.navigateTo({
						url: '../profile/index'
					})
				}
				if (e == 1) {
					uni.navigateTo({
						url: '../list/index'
					})
				}
				if (e == 6) {
					this.$refs.popup.open()
				}
			}
		},
	}
</script>

<style>
	.cover-img {
		width: 100%;
		height: 30upx;
		position: absolute;
		top: -40upx;
	}
	.container {
		width: 100%;
		background: #F4F4F4;
		position: absolute;
		z-index: 3;
	}
.lettel{
	letter-spacing: 25upx;
}
	.imgs-content {
		/* width: 100%; */
		display: flex;
	}

	.imgs-content view image {
		width: 150upx;
		height: 150upx;
		display: inline-block;
	}

	.imgs-content view {
		width: 150upx;
		height: 150upx;
	}

	.cover-img image {
		width: 100%;
		height: 30upx;
	}

	.container {
		width: 100%;
		height: 100%;
	}

	.user-section {
		width: 100%;
		height: 500upx;
		background: url(../../static/temp/user-bg.jpg);
	}

	.container_nav {
		width: 90%;
		height: 100upx;
		float: right;
	}

	.container_nav image {
		width: 50upx;
		height: 50upx;
		margin: 20upx 20upx;
	}

	.container_navContainer {
		display: flex;
		float: right;
	}

	.user-info-box {
		width: 90%;
		height: 170upx;
		margin: auto;
		display: flex;
	}

	.user-info-box view {
		display: flex;
		line-height: 150upx;
	}

	.user-info-box image {
		width: 130upx;
		height: 130upx;
		margin-right: 20upx;
		text-align: center;
	}

	.vip-card-box {
		width: 90%;
		height: 230upx;
		background-color: #443A31;
		margin: auto;
		display: flex;
		opacity: 1;
		border-radius: 10px 10px 0px 0px;
	}

	.vip-card-Text {
		width: 60%;
		line-height: 70upx;
		margin-left: 20upx;
	}

	.vip-card-Text view {
		color: #f6e5a3;

	}

	.vip-card-Text image {
		width: 40upx;
		height: 40upx;
		text-align: center;
		vertical-align: middle;
		display: inline-block;
	}

	.vip-card-img {
		width: 70%;
		height: 100%;
		background: url(../../static/temp/vip-card-bg.png);
		border-radius: 0px 10px 0px 0px;
	}

	.cover-container {
		width: 100%;
		padding: 20upx 0;
		background: #F4F4F4 !important;
		position: absolute;
		top: 330upx;
		padding-bottom: 100upx;
	}

	.order-section {
		width: 90%;
		height: 200upx;
		background: #FFFFFF;
		border-radius: 15upx;
		margin: auto;
		margin-bottom: 20upx;
		display: flex;
		font-size: 25upx;
		justify-content: space-around;
	}

	.order-sectionText {
		margin: 69upx 0px;
	}

	.order-sectionText view {
		width: 100%;
	}

	.order-section image {
		width: 50upx;
		height: 50upx;
		text-align: center;
		margin-left: 20upx;
		margin-bottom: 20upx;
	}

	.history-section {
		width: 90%;
		padding: 20upx 0;
		background: #FFFFFF;
		border-radius: 15upx;
		margin-bottom: 20upx;
		margin: auto;
		font-size: 25upx;
		justify-content: space-around;
		margin-bottom: 20upx;
	}

	.history-Text {
		width: 90%;
		line-height: 80upx;
		margin: auto;
		vertical-align: middle;
	}

	.history-Text view {
		margin: 10upx 0upx;
		text-align: center;
	}

	.history-Text text {
		width: 800upx;
		margin-right: 380upx;
		margin-left: 20upx;
	}

	.history-Text image {
		width: 50upx;
		height: 50upx;
		text-align: center;
		vertical-align: middle;
		display: inline-block;

	}
</style>
